package barcan.flutter.io.image_picker.statusbar;

import androidx.annotation.Nullable;

import java.io.Closeable;
import java.io.IOException;
import java.util.Locale;

/*
 * created by wdlmm1214
 * on 2020/1/9
 */public class QMUILangHelper {
    public QMUILangHelper() {
    }

    public static int getNumberDigits(int number) {
        return number <= 0 ? 0 : (int)(Math.log10((double)number) + 1.0D);
    }

    public static int getNumberDigits(long number) {
        return number <= 0L ? 0 : (int)(Math.log10((double)number) + 1.0D);
    }

    public static String regularizePrice(float price) {
        return String.format(Locale.CHINESE, "%.2f", price);
    }

    public static String regularizePrice(double price) {
        return String.format(Locale.CHINESE, "%.2f", price);
    }

    public static boolean isNullOrEmpty(@Nullable CharSequence string) {
        return string == null || string.length() == 0;
    }

    public static void close(Closeable c) {
        if (c != null) {
            try {
                c.close();
            } catch (IOException var2) {
                var2.printStackTrace();
            }
        }

    }

    public static boolean objectEquals(Object a, Object b) {
        return a == b || a != null && a.equals(b);
    }

    public static int constrain(int amount, int low, int high) {
        return amount < low ? low : (amount > high ? high : amount);
    }

    public static float constrain(float amount, float low, float high) {
        return amount < low ? low : (amount > high ? high : amount);
    }
}
